<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>施工团队</title>
    <style>
    </style>
</head>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=IENn7ABARjQIkTeAKyh80VTkg2jYXf3K"></script>
<body>


<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:">首页</a><span lay-separator="">/</span>
        <a href="javascript:">施工团队</a><span lay-separator="">/</span>
        <a><cite>考勤管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>
<div class="x-body" style="margin: 20px auto auto 15px;">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <a href="base/link/@/constructionTeam/att_management/att_management.jhtml" class="layui-btn">考勤列表</a>
            <a href="base/link/@/constructionTeam/att_management/checkwork.jhtml" class="layui-btn">考勤逐日统计</a>
            <% if (session.om_user.sysRole.sysRoleCode.id==2||session.om_user.sysRole.sysRoleCode.id==3){%>
            <a href="base/link/@/constructionTeam/att_management/checkwork_month.jhtml" class="layui-btn layui-btn-warm">考勤月平均值统计</a>
            <%}%>
        </div>
    </div>

    <div style="margin-left: -15px;" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <input type="hidden"  value="${session.om_user.sysRole.sysRoleCode.id}" id="role_id">
            <input type="hidden"  value="${session.om_user.enterprise.id}" id="e_id">
            <% if (session.om_user.sysRole.sysRoleCode.id==3){%>
            <input type="hidden"  value="${session.area.id}" id="area_id">
            <%}%>
            <div class="layui-input-inline">
                <input type="text" name="starttime" id="startTime" placeholder="查询考勤年份" autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-input-inline" >
                <select type="text" name="a_name" id="a_name1" autocomplete="off" class="layui-select">
                </select>
            </div>
            <div class="layui-input-inline">
                <button id="tips" class="layui-btn layui-btn-checked" lay-submit="" lay-filter="LAY-user-front-search"  ><i class="layui-icon layui-icon-search"></i>查询</button>
            </div>
        </div>
    </div>

    <div class="layui-table-main layui-form" style="height: 100%">
        <table id="myTableData" lay-filter="myTableData"  class="layui-hide"></table>
        <div id="test1"></div>
    </div>
</div>
<!--考勤列表-->
<div class="layui-fluid">
    <div class="layui-card">
        <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
    </div>
    <div class="layui-card" id="ave">
        <table class="layui-table" >
            <thead>
            </thead>
            <tbody>
            <tr>
                <td colspan="2" style="background-color: #009688;color: white">
                    <span id="team_name"></span>人数月度平均值统计
                </td>
            </tr>
            <tr >
                <td colspan="2" ><div id="container4"  style="height:400px"></div></td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<script id="demo4" type="text/html">
    <option value="">请选择施工队</option>
    {{#  layui.each(d.list4, function(index, item4){ }}

    <option value="{{ item4.t_name }}">{{ item4.t_name }}</option>

    {{#  }); }}
    {{#  if(d.list4.length === 0){ }}
    无数据
    {{#  } }}
</script>
<%include("/common/foot.html"){}%>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
<!--施工队月度平均值统计-->
<!--<script type="text/javascript">-->
    <!--var role_id = $("#role_id").val();-->
    <!--var e_id = $("#e_id").val();-->
    <!--var project_id = $("#project_id").val();-->
    <!--var area_id = $("#area_id").val();-->
    <!--$.ajax({-->
        <!--url: "system/att_checkwork/statisMon.json",-->
        <!--type: "POST",-->
        <!--data: {-->
            <!--role_id:role_id,-->
            <!--e_id:e_id,-->
            <!--project_id: project_id,-->
            <!--area_id: area_id,-->
        <!--},-->
        <!--dataType: "json",-->
        <!--success: function (data) {-->
            <!--let worklist = [];-->
            <!--if(role_id==2||role_id==3){-->
                <!--$("#team_name").text("所有施工队");-->
            <!--}-->
            <!--for(var i =0;i<data.worklist.length;i++){-->
                <!--worklist.push(data.worklist[i]);-->
            <!--}-->
            <!--var dom = document.getElementById("container4");-->
            <!--var myChart = echarts.init(dom);-->
            <!--var app = {};-->
            <!--option = null;-->
            <!--option = {-->
                <!--tooltip: {-->
                    <!--trigger: 'axis'-->
                <!--},-->
                <!--legend: {-->
                    <!--data: ['2020']-->
                <!--},-->
                <!--toolbox: {-->
                    <!--show: true,-->
                    <!--feature: {-->
                        <!--dataView: {show: true, readOnly: false},-->
                        <!--magicType: {show: true, type: ['line', 'bar']},-->
                        <!--restore: {show: true},-->
                        <!--saveAsImage: {show: true}-->
                    <!--}-->
                <!--},-->
                <!--calculable: true,-->
                <!--xAxis: [-->
                    <!--{-->
                        <!--type: 'category',-->
                        <!--data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']-->
                    <!--}-->
                <!--],-->
                <!--yAxis: [-->
                    <!--{-->
                        <!--type: 'value',-->
                    <!--}-->
                <!--],-->
                <!--series: [-->
                    <!--{-->
                        <!--name: '月平均出勤人数',-->
                        <!--type: 'bar',-->
                        <!--data: worklist-->
                    <!--}-->
                <!--]-->
            <!--};-->
            <!--if (option && typeof option === "object") {-->
                <!--myChart.setOption(option, true);-->
            <!--}-->
        <!--}-->
    <!--});-->
<!--</script>-->
<!--考勤列表-->
<script>
    $("#ave").hide();
    layui.use(['index', 'table', 'form', 'laydate', 'AliangLayui'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        var title = "考勤";
        var findAll_url = 'system/att_checkwork/findCheck_month.json';
        var find_Cols = 'system/att_checkwork/findCols_month.json'

        var e_id = $("#e_id").val();
        var role_id = $("#role_id").val();
        var project_id = $("#project_id").val();
        var area_id = $("#area_id").val();
        var mycols = new Array;
        $.ajax({
            url: find_Cols,
            type: "POST",
            data: {
                e_id: e_id,
                role_id: role_id,
                project_id: project_id,
                area_id: area_id,
            },
            async:false,
            dataType: "json",
            success: function (ret) {
                if(ret.code==0){
                    for(var i =0;i<ret.data.length;i++) {
                        mycols[0] = {
                            field: 'c_mon',
                            fixed: 'left',
                            title: '考勤月份',
                            align: 'center',
                        };
                        if(role_id==2||role_id==3){
                            mycols[1] = {
                                field: 'c_ave',
                                sort: 'true',
                                title: '人数月平均值',
                                align: 'center',
                            };
                        }
                        if(role_id==2||role_id==3){
                            mycols[2] = {
                                field: 'c_name',
                                sort: 'true',
                                title: '施工队名称',
                                align: 'center',
                            };
                        }
                    }
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
            }
        });



        //考勤列表
        table.render({
            elem: '#LAY-user-manage',
            id: 'listReload',
            toolbar: '#toolbarDemo',
            title: title,
            url: findAll_url,
            page: true, //开启分页
            limit:12,
            limits: [12, 24, 36, 48], //控制多少行一页（默认五条一页）
            defaultToolbar: ['filter', 'print', 'exports'],
            cols: [mycols],
            where:{
                e_id:$("#e_id").val(),
                role_id:$("#role_id").val(),
                project_id:$("#project_id").val(),
                area_id:$("#area_id").val()
            },
            done: function (res, curr, count) {

                // 合并纵行
                mergeRows(2);

                //将合计数值去小数点
                $(".layui-table-total div").each(function (i,item) {
                    var div_text = $(item).html();
                    var value; //转换后的值
                    if(div_text != "") {
                        value = parseInt(div_text);
                        if(!isNaN(value)) {
                            $(item).html(parseInt(div_text));
                        }
                    }
                });
            }
        });

        /**
         * 合并第几列
         * @param index 列的下标,从0开始
         * @param tr 需要的tr dom对象，非必传
         */
        function mergeRows(index, tr) {
            // 根据选择器找到表格的tr.根据情况自己修改
            let _tr = $('.layui-table tr');
            if (tr) {
                _tr = tr;
            }
            let mergeStr = '', oldName, newName, countNum = 0;
            for (let i = 0, trLength = _tr.length; i < trLength; i++) {
                newName = $(_tr[i]).find('div:eq(' + index + ')').text();
                if (i == 0 || newName == oldName) {
                    countNum++;
                } else {
                    mergeStr += countNum + ",";
                    mergeStr += Array(countNum).join(0 + ",");
                    countNum = 1;
                }
                oldName = newName;
            }
            mergeStr += countNum + ",";
            mergeStr += Array(countNum).join(0 + ",");

            // 上面计算得到的合并参照信息.
            // 格式参考:40003002050000
            // 解释:从左到右,4表示合并4行,0表示设定display:none
            let mergeArr = mergeStr.split(",");
            mergeArr.pop();
            let cssNum = 0;
            for (let i = 0, length = mergeArr.length; i < length; i++) {
                let e = $(_tr[i]).find('td:eq(' + index + ')');
                if (mergeArr[i] != '0') {
                    // 合并行
                    e.attr('rowspan', mergeArr[i]);
                } else {
                    e.css('display', 'none');
                }
            }
        }

        //搜索栏队伍
        var eid = $("#e_id").val();
        var roleid = $("#role_id").val();
        if(roleid==3){
            var areaid = $("#area_id").val();
        }
        $.ajax({
            url: "system/constructionTeam/findAreaTeam.json",
            type: "POST",
            data: {
                eid:eid,
                roleid:roleid,
                areaid:areaid
            },
            dataType: "json",
            success: function (ret4) {
                var laytpl = layui.laytpl;
                var rets = { //数据
                    "list4": ret4.data,
                };
                laytpl($("#demo4").html()).render(rets, function (html) {
                    $("#a_name1").html(html);
                });
                form.render();
            },
            error: function (jqXHR, textStatus, errorThrown) {

            }
        });

        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            var e_id = $("#e_id").val();
            var role_id = $("#role_id").val();
            var project_id = $("#project_id").val();
            var area_id = $("#area_id").val();
            var mycols = new Array;
            if(field.starttime==""||field.a_name==""){
                layer.tips('请同时选择年份及队伍', '#tips');
            }
            if(field.starttime!=""&&field.a_name!=""){
                $.ajax({
                    url: find_Cols,
                    type: "POST",
                    data: {
                        e_id: e_id,
                        role_id: role_id,
                        project_id: project_id,
                        area_id: area_id,
                        starttime: field.starttime,
                        a_name: field.a_name
                    },
                    async:false,
                    dataType: "json",
                    success: function (ret) {
                        if(ret.code==0){
                            for(var i =0;i<ret.data.length;i++) {
                                mycols[0] = {
                                    totalRowText: '合计：',
                                    unresize: true,
                                    field: 'c_mon',
                                    fixed: 'left',
                                    title: '考勤月份',
                                    align: 'center',
                                };
                                mycols[1] = {
                                    field: 'c_ave',
                                    sort: 'true',
                                    title: ret.data[0].c_name+'人数月平均值',
                                    align: 'center',
                                };
                                mycols[2] = {
                                    field: 'c_name',
                                    sort: 'true',
                                    title: '施工队名称',
                                    align: 'center',
                                };
                            };
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                    }
                });
                var role_id = $("#role_id").val();
                var e_id = $("#e_id").val();
                var project_id = $("#project_id").val();
                var area_id = $("#area_id").val();
                $.ajax({
                    url: "system/att_checkwork/statisMon.json",
                    type: "POST",
                    data: {
                        role_id: role_id,
                        e_id:e_id,
                        project_id: project_id,
                        area_id: area_id,
                        starttime: field.starttime,
                        a_name: field.a_name
                    },
                    dataType: "json",
                    success: function (data) {
                        $("#team_name").text(data.name);

                        let worklist = [];
                        for(var i =0;i<data.worklist.length;i++){
                            worklist.push(data.worklist[i]);
                        }
                        var dom = document.getElementById("container4");
                        var myChart = echarts.init(dom);
                        var app = {};
                        option = null;
                        option = {
                            tooltip: {
                                trigger: 'axis'
                            },
                            legend: {
                                data: ['2020']
                            },
                            toolbox: {
                                show: true,
                                feature: {
                                    dataView: {show: true, readOnly: false},
                                    magicType: {show: true, type: ['line', 'bar']},
                                    restore: {show: true},
                                    saveAsImage: {show: true}
                                }
                            },
                            calculable: true,
                            xAxis: [
                                {
                                    type: 'category',
                                    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value',
                                }
                            ],
                            series: [
                                {
                                    name: '月平均出勤人数',
                                    type: 'bar',
                                    data: worklist
                                }
                            ]
                        };
                        if (option && typeof option === "object") {
                            myChart.setOption(option, true);
                        }
                    }
                });
                //执行重载
                table.reload('listReload', {
                    where: {
                        starttime: field.starttime,
                        a_name: field.a_name
                    },
                    page: {
                        curr: 1//重新从第 1 页开始
                    },
                    cols: [mycols]//重载时必须重新定义表头为自己定义的表头，否则默认layui表头，无法渲染
                });
                $("#ave").show();
            }
        });

        //执行laydate
        laydate.render({
            elem: '#startTime', //指定元素
            type: 'year',

        });

        //头工具栏事件
        table.on('toolbar(LAY-user-manage)', function (obj) {
            switch (obj.event) {
                case 'export':
                    layer.msg("导出");
                    break;
            }
        });
    });
</script>

</body>

</html>
